package com.ezhuan.task.service.impl;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ezhuan.common.service.BaseServiceImpl;
import com.ezhuan.common.util.ConstatFinalUtil;
import com.ezhuan.common.util.PageInfoUtil;
import com.ezhuan.task.dao.IATaskDao;
import com.ezhuan.task.dao.impl.ATaskDaoImpl;
import com.ezhuan.task.pojo.ATask;
import com.ezhuan.task.service.ITaskService;

public class TaskServiceImpl extends BaseServiceImpl implements ITaskService
{
	private IATaskDao taskDao = new ATaskDaoImpl();
	
	@Override
	public JSONObject saveOneTaskService(ATask task)
	{
		JSONObject resultJSON = new JSONObject();
		/* 保存记录 */
		boolean flag = this.taskDao.save(task);
		if(flag)
		{
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", task.getId() + "");
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
		}else
		{
			resultJSON.put("code", "3");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("3"));
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneTaskService(ATask task)
	{
		JSONObject resultJSON = new JSONObject();
		/* 保存记录 */
		boolean flag = this.taskDao.update(task);
		if(flag)
		{
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", task.getId() + "");
			resultJSON.put("data", dataJSON);
			
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
		}else
		{
			resultJSON.put("code", "3");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("3"));
		}
		return resultJSON;
	}

	@Override
	public ATask findOneTaskService(Map<String, Object> condMap)
	{
		return this.taskDao.findOneDao(condMap);
	}

	@Override
	public List<ATask> findCondListTaskService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		return this.taskDao.findCondListDao(pageInfoUtil, condMap);
	}
}
